﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using FineUI;

namespace lcmyjobs.Web.users
{
    public partial class user_main : BasePage
    {
        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Title = string.Format("个人管理中心：首页   {0}", Application["webname"].ToString());
                if (Session["user_id"] == null)
                {
                    Response.Redirect("userlogin.html");
                }
                else
                {
                    int id = int.Parse(Session["user_id"].ToString());
                    this.lblName.Text = Session["user_name"].ToString();
                    showme(id);
                }
            }
        }
        public void showme(int id)
        {
            lcmyjobs.BLL.user_basic bad = new BLL.user_basic();
            DataSet ds = bad.GetUserMain(id);
   
            if (ds.Tables[0].Rows.Count > 0)
            {
                // 判断用户是否注册完成 add by liuhui 131102
                if(ds.Tables[0].Rows[0]["isregok"].ToString() == "3"){
                    Session["user_id_reg"] = Session["user_id"];
                    Session["user_id"] = null;
                    //Session["user_name"] = null;
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "您还没有完成注册，请先完成注册！", "reg_edu.html");
                }
                else if (ds.Tables[0].Rows[0]["isregok"].ToString() == "2")
                {
                    Session["user_id_reg"] = Session["user_id"];
                    Session["user_id"] = null;
                    //Session["user_name"] = null;
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "您还没有填写简历，请先填写简历！", "reg_job.html");
                }

                if (ds.Tables[0].Rows[0][0].ToString() == "未审核")
                    //lblstatus0.Text = "原因是管理员还没有处理或您的简历虚假；请一周内修改简历，否则将被删除；";
                    lblstatus0.Text = "原因是管理员还没有处理";
                else
                    lblstatus0.Text = "已是我就业网正式会员，祝福您早日找到合适工作；";
                lblstatus.Text = ds.Tables[0].Rows[0][0].ToString();
                lbljobsta.Text = ds.Tables[0].Rows[0][1].ToString();
                string text = ds.Tables[0].Rows[0][2].ToString();
                if (text == "不公开")
                {
                    lbllink.Text = text + "，保密；允许浏览，点击";
                    lbtnshow.Text = "公开";
                }
                else
                {
                    lbllink.Text = text + "，允许浏览；不允许浏览，点击";
                    lbtnshow.Text = "隐藏";
                }
                int nums = int.Parse(ds.Tables[0].Rows[0][4].ToString());
                string time = "";
                if (Session["user_time"] != null)
                {
                    time = Session["user_time"].ToString();
                }
                else
                {
                    time = ds.Tables[0].Rows[0][5].ToString();
                }
                lblTime.Text = string.Format("您是第{0}次登录，今天还可登录{1}次；您上次登录： {2}；", ds.Tables[0].Rows[0][3].ToString(), 15 - nums, time);


            }
            if (ds.Tables[1].Rows.Count > 0)
            {
                lblms.Text = ds.Tables[1].Rows[0][0].ToString();
            }
            if (ds.Tables[2].Rows.Count > 0)
            {
                lblms0.Text = ds.Tables[2].Rows[0][0].ToString();
            }
            if (ds.Tables[3].Rows.Count > 0)
            {
                lblms1.Text = ds.Tables[3].Rows[0][0].ToString();
            }
            if (ds.Tables[4].Rows.Count > 0)
            {
                lblms2.Text = ds.Tables[4].Rows[0][0].ToString();
            }
            if (ds.Tables[5].Rows.Count > 0)
            {
                lblms3.Text = ds.Tables[5].Rows[0][0].ToString();
            }
            if (ds.Tables[6].Rows.Count > 0)
            {
                lblms4.Text = ds.Tables[6].Rows[0][0].ToString();
            }
            if (ds.Tables[7].Rows.Count > 0)
            {
                lblms5.Text = ds.Tables[7].Rows[0][0].ToString();
            }
            if (ds.Tables[8].Rows.Count > 0)
            {
                int i = int.Parse(ds.Tables[8].Rows[0][0].ToString());
                if (i == 3)
                {
                    this.lblstatus0.Text = "，您的信息不完整，请进入<a href='reg_edu.html' class='ma'>个人注册中心</a>完善信息";
                }
            }

        }

        protected void lbtnshow_Click(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {
                int uid = int.Parse(Session["user_id"].ToString());
                int r = 0;
                LinkButton lb = (LinkButton)sender;
                if (lb.Text == "公开")
                {
                    r = bub.changelink(uid, 1);

                }
                else
                {
                    r = bub.changelink(uid, 0);

                }
                if (r != 0)
                {
                    Maticsoft.Common.MessageBox.Show(this, "修改成功！");
                    //Alert.Show("修改成功！");
                    showme(uid);
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "修改失败！");
                    //Alert.Show("修改失败！");
                }
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {
                int uid = int.Parse(Session["user_id"].ToString());
                int r = 0;
                r = bub.updateusertime(uid);
                if (r != 0)
                {
                    Maticsoft.Common.MessageBox.Show(this, "刷新成功！");
                    //Alert.Show("刷新成功！");
                    //LinkButton1.Enabled = false;
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "刷新失败！");
                    //Alert.Show("刷新失败！");
                }
            }

        }
    }
}